package gov.army.workshop.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="EQMS_WORKORDER")
@Searchable
public class Workorder extends BaseObject{
	/**
	 * 
	 */
	private static final long serialVersionUID = -2621997935501270287L;
	
	public  static String version="IAFO-1370";
	private Long id;
	private String workorderNo;
	private Date woCreationDate;
	private String authority;
	private String priority;
	private Boolean mfr;
	private Boolean repair;
	private Boolean depositeRepair;
	private Boolean payment;
	private String woPlacedBy;
	private String woPlacedByUnit;
	private String woPlacedByStation;
	private String woPlacedBySubDepot;
	private String woPlacedOnUnit;
	private String woPlacedOnStation;
	private String woPlacedOnSubDepot;
	private Date pssDate;
	private String review;
	private String priorityCategory;
	private String workshopSection;
	private JobDetail job;
	//private Equipment equipment;
	private List<WorkItem> workItemList=new ArrayList<WorkItem>();	
	private List<Payment> payments= new ArrayList<Payment>();
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @SearchableId
    public Long getId() {
        return id;
    }
    
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}


	/**
	 * @return the workorderNo
	 */
	@Column(name = "WORKORDER_NO", nullable = false, length = 50)
    @SearchableProperty
	public String getWorkorderNo() {
		return workorderNo;
	}
	/**
	 * @return the woCreationDate
	 */
	@Column(name = "WORKORDER_CREATION_DATE", nullable = false)
    @SearchableProperty
	public Date getWoCreationDate() {
		return woCreationDate;
	}
	/**
	 * @return the authority
	 */
	@Column(name = "AUTHORITY")
    @SearchableProperty
	public String getAuthority() {
		return authority;
	}
	/**
	 * @return the priority
	 */
	@Column(name = "PRIORITY")
    @SearchableProperty
	public String getPriority() {
		return priority;
	}
	/**
	 * @return the mfr
	 */
	@Column(name = "FLAG_MFR")
    @SearchableProperty
	public Boolean getMfr() {
		return mfr;
	}
	/**
	 * @return the repair
	 */
	@Column(name = "FLAG_REPAIR")
    @SearchableProperty
	public Boolean getRepair() {
		return repair;
	}
	/**
	 * @return the depositeRepair
	 */
	@Column(name = "FLAG_DEPOSITE_REPAIR")
    @SearchableProperty
	public Boolean getDepositeRepair() {
		return depositeRepair;
	}
	/**
	 * @return the payment
	 */
	@Column(name = "FLAG_PAYMENT")
    @SearchableProperty
	public Boolean getPayment() {
		return payment;
	}
	/**
	 * @return the woPlacedBy
	 */
	@Column(name = "WO_PLACED_BY", nullable=false,length=100)
    @SearchableProperty
	public String getWoPlacedBy() {
		return woPlacedBy;
	}
	/**
	 * @return the woPlacedByUnit
	 */
	@Column(name = "WO_PLACED_BY_UNIT", nullable=false,length=100)
    @SearchableProperty
	public String getWoPlacedByUnit() {
		return woPlacedByUnit;
	}
	/**
	 * @return the woPlacedByStation
	 */
	@Column(name = "WO_PLACED_BY_STATION", nullable=false,length=100)
    @SearchableProperty
	public String getWoPlacedByStation() {
		return woPlacedByStation;
	}
	/**
	 * @return the woPlacedBySubDepot
	 */
	@Column(name = "WO_PLACED_BY_SUB_DEPOT", nullable=true,length=100)
    @SearchableProperty
	public String getWoPlacedBySubDepot() {
		return woPlacedBySubDepot;
	}
	/**
	 * @return the woPlacedOnUnit
	 */
	@Column(name = "WO_PLACED_ON_UNIT", nullable=false,length=100)
    @SearchableProperty
	public String getWoPlacedOnUnit() {
		return woPlacedOnUnit;
	}
	/**
	 * @return the woPlacedOnStation
	 */
	@Column(name = "WO_PLACED_ON_STATION", nullable=false,length=100)
    @SearchableProperty
	public String getWoPlacedOnStation() {
		return woPlacedOnStation;
	}
	/**
	 * @return the woPlacedOnSubDepot
	 */
	@Transient
	public String getWoPlacedOnSubDepot() {
		return woPlacedOnSubDepot;
	}
	/**
	 * @return the pssDate
	 */
	@Column(name = "WO_PSS_DATE")
    @SearchableProperty
	public Date getPssDate() {
		return pssDate;
	}
	/**
	 * @return the review
	 */
	@Column(name = "WO_REVIEW")
    @SearchableProperty
	public String getReview() {
		return review;
	}
	/**
	 * @return the priorityCategory
	 */
	@Column(name = "WO_PRIPRITY_CATEGORY")
    @SearchableProperty
	public String getPriorityCategory() {
		return priorityCategory;
	}
	/**
	 * @return the workshopSection
	 */
	@Column(name = "WO_WORKSHOP_SECTION", nullable=true,length=100)
    @SearchableProperty
	public String getWorkshopSection() {
		return workshopSection;
	}
	/**
	 * @return the job
	 */
	@OneToOne( fetch=FetchType.EAGER )
    @JoinColumn(name="WO_JOB_ID", nullable=true)
	public JobDetail getJob() {
		return job;
	}
	
//	/**
//	 * @return the equipment
//	 */
//	@OneToOne( fetch=FetchType.EAGER )
//    @JoinColumn(name="WO_EQUIPMENT_ID", nullable=false)
//	public Equipment getEquipment() {
//		return equipment;
//	}
	/**
	 * @return the workItemList
	 */
	@OneToMany(mappedBy="workorder")
	public List<WorkItem> getWorkItemList() {
		return workItemList;
	}
	/**
	 * @return the receipts
	 */
	@OneToMany(mappedBy="workorder")
	public List<Payment> getReceipts() {
		return payments;
	}
	/**
	 * @param workorderNo the workorderNo to set
	 */
	public void setWorkorderNo(String workorderNo) {
		this.workorderNo = workorderNo;
	}
	/**
	 * @param woCreationDate the woCreationDate to set
	 */
	public void setWoCreationDate(Date woCreationDate) {
		this.woCreationDate = woCreationDate;
	}
	/**
	 * @param authority the authority to set
	 */
	public void setAuthority(String authority) {
		this.authority = authority;
	}
	/**
	 * @param priority the priority to set
	 */
	public void setPriority(String priority) {
		this.priority = priority;
	}
	/**
	 * @param mfr the mfr to set
	 */
	public void setMfr(Boolean mfr) {
		this.mfr = mfr;
	}
	/**
	 * @param repair the repair to set
	 */
	public void setRepair(Boolean repair) {
		this.repair = repair;
	}
	/**
	 * @param depositeRepair the depositeRepair to set
	 */
	public void setDepositeRepair(Boolean depositeRepair) {
		this.depositeRepair = depositeRepair;
	}
	/**
	 * @param payment the payment to set
	 */
	public void setPayment(Boolean payment) {
		this.payment = payment;
	}
	/**
	 * @param woPlacedBy the woPlacedBy to set
	 */
	public void setWoPlacedBy(String woPlacedBy) {
		this.woPlacedBy = woPlacedBy;
	}
	/**
	 * @param woPlacedByUnit the woPlacedByUnit to set
	 */
	public void setWoPlacedByUnit(String woPlacedByUnit) {
		this.woPlacedByUnit = woPlacedByUnit;
	}
	/**
	 * @param woPlacedByStation the woPlacedByStation to set
	 */
	public void setWoPlacedByStation(String woPlacedByStation) {
		this.woPlacedByStation = woPlacedByStation;
	}
	/**
	 * @param woPlacedBySubDepot the woPlacedBySubDepot to set
	 */
	public void setWoPlacedBySubDepot(String woPlacedBySubDepot) {
		this.woPlacedBySubDepot = woPlacedBySubDepot;
	}
	/**
	 * @param woPlacedOnUnit the woPlacedOnUnit to set
	 */
	public void setWoPlacedOnUnit(String woPlacedOnUnit) {
		this.woPlacedOnUnit = woPlacedOnUnit;
	}
	/**
	 * @param woPlacedOnStation the woPlacedOnStation to set
	 */
	public void setWoPlacedOnStation(String woPlacedOnStation) {
		this.woPlacedOnStation = woPlacedOnStation;
	}
	/**
	 * @param woPlacedOnSubDepot the woPlacedOnSubDepot to set
	 */
	public void setWoPlacedOnSubDepot(String woPlacedOnSubDepot) {
		this.woPlacedOnSubDepot = woPlacedOnSubDepot;
	}
	/**
	 * @param pssDate the pssDate to set
	 */
	public void setPssDate(Date pssDate) {
		this.pssDate = pssDate;
	}
	/**
	 * @param review the review to set
	 */
	public void setReview(String review) {
		this.review = review;
	}
	/**
	 * @param priorityCategory the priorityCategory to set
	 */
	public void setPriorityCategory(String priorityCategory) {
		this.priorityCategory = priorityCategory;
	}
	/**
	 * @param workshopSection the workshopSection to set
	 */
	public void setWorkshopSection(String workshopSection) {
		this.workshopSection = workshopSection;
	}
	/**
	 * @param job the job to set
	 */
	public void setJob(JobDetail job) {
		this.job = job;
	}
	/**
	 * @param workItemList the workItemList to set
	 */
	public void setWorkItemList(List<WorkItem> workItemList) {
		this.workItemList = workItemList;
	}
	/**
	 * @param receipts the receipts to set
	 */
	public void setReceipts(List<Payment> payments) {
		this.payments = payments;
	}
	
	
//	/**
//	 * @param equipment the equipment to set
//	 */
//	public void setEquipment(Equipment equipment) {
//		this.equipment = equipment;
//	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Workorder other = (Workorder) obj;
		if (authority == null) {
			if (other.authority != null)
				return false;
		} else if (!authority.equals(other.authority))
			return false;
		if (depositeRepair == null) {
			if (other.depositeRepair != null)
				return false;
		} else if (!depositeRepair.equals(other.depositeRepair))
			return false;
		if (mfr == null) {
			if (other.mfr != null)
				return false;
		} else if (!mfr.equals(other.mfr))
			return false;
		if (payment == null) {
			if (other.payment != null)
				return false;
		} else if (!payment.equals(other.payment))
			return false;
		if (priority == null) {
			if (other.priority != null)
				return false;
		} else if (!priority.equals(other.priority))
			return false;
		if (priorityCategory == null) {
			if (other.priorityCategory != null)
				return false;
		} else if (!priorityCategory.equals(other.priorityCategory))
			return false;
		if (pssDate == null) {
			if (other.pssDate != null)
				return false;
		} else if (!pssDate.equals(other.pssDate))
			return false;
		
		if (repair == null) {
			if (other.repair != null)
				return false;
		} else if (!repair.equals(other.repair))
			return false;
		if (review == null) {
			if (other.review != null)
				return false;
		} else if (!review.equals(other.review))
			return false;
		if (version == null) {
			if (other.version != null)
				return false;
		} else if (!version.equals(other.version))
			return false;
		if (woCreationDate == null) {
			if (other.woCreationDate != null)
				return false;
		} else if (!woCreationDate.equals(other.woCreationDate))
			return false;
		if (woPlacedBy == null) {
			if (other.woPlacedBy != null)
				return false;
		} else if (!woPlacedBy.equals(other.woPlacedBy))
			return false;
		if (woPlacedByStation == null) {
			if (other.woPlacedByStation != null)
				return false;
		} else if (!woPlacedByStation.equals(other.woPlacedByStation))
			return false;
		if (woPlacedBySubDepot == null) {
			if (other.woPlacedBySubDepot != null)
				return false;
		} else if (!woPlacedBySubDepot.equals(other.woPlacedBySubDepot))
			return false;
		if (woPlacedByUnit == null) {
			if (other.woPlacedByUnit != null)
				return false;
		} else if (!woPlacedByUnit.equals(other.woPlacedByUnit))
			return false;
		if (woPlacedOnStation == null) {
			if (other.woPlacedOnStation != null)
				return false;
		} else if (!woPlacedOnStation.equals(other.woPlacedOnStation))
			return false;
		if (woPlacedOnSubDepot == null) {
			if (other.woPlacedOnSubDepot != null)
				return false;
		} else if (!woPlacedOnSubDepot.equals(other.woPlacedOnSubDepot))
			return false;
		if (woPlacedOnUnit == null) {
			if (other.woPlacedOnUnit != null)
				return false;
		} else if (!woPlacedOnUnit.equals(other.woPlacedOnUnit))
			return false;
		if (workItemList == null) {
			if (other.workItemList != null)
				return false;
		} else if (!workItemList.equals(other.workItemList))
			return false;
		if (workorderNo == null) {
			if (other.workorderNo != null)
				return false;
		} else if (!workorderNo.equals(other.workorderNo))
			return false;
		if (workshopSection == null) {
			if (other.workshopSection != null)
				return false;
		} else if (!workshopSection.equals(other.workshopSection))
			return false;
		return true;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((authority == null) ? 0 : authority.hashCode());
		result = prime * result
				+ ((depositeRepair == null) ? 0 : depositeRepair.hashCode());
		result = prime * result + ((job == null) ? 0 : job.hashCode());
		result = prime * result + ((mfr == null) ? 0 : mfr.hashCode());
		result = prime * result + ((payment == null) ? 0 : payment.hashCode());
		result = prime * result
				+ ((priority == null) ? 0 : priority.hashCode());
		result = prime
				* result
				+ ((priorityCategory == null) ? 0 : priorityCategory.hashCode());
		result = prime * result + ((pssDate == null) ? 0 : pssDate.hashCode());
		result = prime * result + ((repair == null) ? 0 : repair.hashCode());
		result = prime * result + ((review == null) ? 0 : review.hashCode());
		result = prime * result + ((version == null) ? 0 : version.hashCode());
		result = prime * result
				+ ((woCreationDate == null) ? 0 : woCreationDate.hashCode());
		result = prime * result
				+ ((woPlacedBy == null) ? 0 : woPlacedBy.hashCode());
		result = prime
				* result
				+ ((woPlacedByStation == null) ? 0 : woPlacedByStation
						.hashCode());
		result = prime
				* result
				+ ((woPlacedBySubDepot == null) ? 0 : woPlacedBySubDepot
						.hashCode());
		result = prime * result
				+ ((woPlacedByUnit == null) ? 0 : woPlacedByUnit.hashCode());
		result = prime
				* result
				+ ((woPlacedOnStation == null) ? 0 : woPlacedOnStation
						.hashCode());
		result = prime
				* result
				+ ((woPlacedOnSubDepot == null) ? 0 : woPlacedOnSubDepot
						.hashCode());
		result = prime * result
				+ ((woPlacedOnUnit == null) ? 0 : woPlacedOnUnit.hashCode());
		result = prime * result
				+ ((workItemList == null) ? 0 : workItemList.hashCode());
		result = prime * result
				+ ((workorderNo == null) ? 0 : workorderNo.hashCode());
		result = prime * result
				+ ((workshopSection == null) ? 0 : workshopSection.hashCode());
		return result;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Workorder [version=" + version + ", workorderNo=" + workorderNo
				+ ", woCreationDate=" + woCreationDate + ", authority="
				+ authority + ", priority=" + priority + ", mfr=" + mfr
				+ ", repair=" + repair + ", depositeRepair=" + depositeRepair
				+ ", payment=" + payment + ", woPlacedBy=" + woPlacedBy
				+ ", woPlacedByUnit=" + woPlacedByUnit + ", woPlacedByStation="
				+ woPlacedByStation + ", woPlacedBySubDepot="
				+ woPlacedBySubDepot + ", woPlacedOnUnit=" + woPlacedOnUnit
				+ ", woPlacedOnStation=" + woPlacedOnStation
				+ ", woPlacedOnSubDepot=" + woPlacedOnSubDepot + ", pssDate="
				+ pssDate + ", review=" + review + ", priorityCategory="
				+ priorityCategory + ", workshopSection=" + workshopSection
				+ ", job=" + job + ", workItemList=" + workItemList+"]";
	}
}
